<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page isELIgnored="false"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
    <base href="<%=basePath%>">
    <title>用户列表</title>
    <script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <style type="text/css">
        a {
            border: 1px solid rgb(73, 58, 58);
            background-color: rgb(133, 133, 133);
            height: 50px;
            line-height: 50px;
            color: white;
            text-decoration: none;
            font-weight: bold;
            padding: 5px;
            margin: 5px;
        }
    </style>
    <script type="text/javascript">

        function deleteUser(id){
            $.ajax({
                type: 'delete',
                url:'<%=basePath%>user/'+id,
                dataType:'json',
                success:function(data){
                    if(data=="suc"){
                        alert("删除成功");
                        location.href="<%=basePath%>user";
                    }
                },
                error:function(data){
                }
            });
        }

    </script>
    <script>　　
        function ajaxfresh(url){
            $.ajax({
                type : "get",
                async : false,
                url : '<%=basePath%>user/ajax/'+url,
                success : function(page){
                    alert(page);
                    $("#mainContent").html(page);
                },
                error : function(){
                    console.log("faild");
                }
            });
        }　　　　


    </script>
</head>

<body>
<div style="margin:0 auto;width:500px;">
    <a href="<%=basePath%>user/add">新增用户</a>
    <a href="#" onclick="ajaxfresh('test1.html')">click</a>
    <div id="mainContent"></div>
    <table>
        <tr>
            <th>用户ID</th>
            <th>用户名称</th>
            <th>操作</th>
        </tr>
        <c:forEach var="user" items="${list}">
            <tr>
                <td>${user.userId }</td>
                <td>${user.userName }</td>
                <td>
                    <a href="<%=basePath %>user/${user.userId}/edit">编辑用户</a>
                    <a href="<%=basePath %>user/${user.userId}/viewUser">查看用户</a>
                    <a href="javascript:void(0);" onclick="deleteUser(${user.userId })">删除该用户</a>
                </td>
            </tr>
        </c:forEach>
    </table>
</div>
</body>

</html>